<?php
/**
 * @author DXing1202 <dxing1202@outlook.com>
 * @copyright dxing1202.cn
 * @time 2018/2/24
 * @Licensed GPL
 */
namespace app\admin\controller;

use think\Controller;
use think\captcha\Captcha;
use app\admin\model\Admins as AdminsModel;
use think\facade\Session;

/**
* Login 控制器 [后台登陆]
* Class Login
* @package app\admin\controller
*/
class Login extends Controller{

  /**
   * 后台登录
   * @return 模版 渲染模版
   */
  public function login(){
    if($this->request->isAjax()){
      //  获取用户登录时候的用户名、密码、验证码
      $adminsName = $this->request->param('adminsName');
      $password = $this->request->param('password');
      $code = $this->request->param('code');

      $captcha = new Captcha();
      if(!$captcha->check($code)){
        return "验证码错误";
      }

      return AdminsModel::checkLogin($adminsName,$password);
    }

    return $this->fetch();
  }

  public function logout(){
    Session::pull('id');
    Session::pull('adminsName');
    $this->redirect('admin/login/login');
  }


}
